package net.slenderloris.TouchServer;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.bluetooth.LocalDevice;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

public class BtSocketServer {
		
    private final LocalDevice mLocalDevice;
    private StreamConnection mConnection;

    public BtSocketServer() throws IOException {
        mLocalDevice = LocalDevice.getLocalDevice();
    }

    public DataInputStream getBtInputStream() throws IOException {
    	StreamConnectionNotifier scn = (StreamConnectionNotifier) Connector.open("btspp://localhost:" +
            "01B99DA0749F11E2BCFD0800200C9A66;name=BtExample;" +
            "authenticate=false;encrypt=false;master=false");
        System.out.println("accepting on " + mLocalDevice.getBluetoothAddress());
        mConnection = scn.acceptAndOpen();
        return mConnection.openDataInputStream();
    }
    
    public void close() throws IOException {
    	mConnection.close();
    }

}
